/**
 * Created by cherry
 */

import api from '../../api/api';
import * as types from '../mutation';


const state = {
  cart:{
    list:[],
    usually:[]
  }
};

const getters = {
    cartedList: state => state.cart.list,
    usuallyList:state=>state.cart.usually
};

const actions = {
  /*
   * 获取首页列表
   * */
  getCartList ({ commit }) {
      api.getCartList(function (res) {
        commit(types.ALL_CART_LIST_SUCCESS, { res });
      })
  },
  getUsually({commit}){
      api.getUsuallyList(function(res){
        commit(types.ALL_USUALLY_LIST_SUCCESS,{res});
      })
  }
}

const mutations = {
  [types.ALL_CART_LIST_SUCCESS] (state, { res }) {
      state.cart.list = res;
  },
  [types.ALL_USUALLY_LIST_SUCCESS](state,{res}){
    state.cart.usually=res;
  }
};


export default{
    state,
    getters,
    actions,
    mutations
}
